(function() {

  function checkMobile(str) {
    var re = /^1\d{10}$/;
    if (re.test(str)) {
      return true;
    } else {
      return false;
    }
  }

  function checkCode(str) {
    var re = /^\d{4,6}$/;
    if (re.test(str)) {
      return true;
    } else {
      return false;
    }
  }
  var c = 60,
    t;
  //倒时器
  function pourtime(callstep, callback) {
    c--;
    callstep(c);
    if (c < 0) {
      clearTimeout(t);
      callback();
    } else {
      t = setTimeout(function() {
        pourtime(callstep, callback);
      }, 1000);
    }
  }

  var _options = {
    size: '24px',
    imgPath: 'img'
  };

  function imgNum(num) {
    var arr = ('' + num).split('');
    var html = '';
    for (var i = 0; i < arr.length; i++) {
      html += '<img style="height:' + _options.size + '"> src="' + _options.imgPath + '"/' + i + '.png" />';
    }
    return html;
  }

  imgNum.set = function(options) {
    _options = {
      size: options.size || _options.size,
      imgPath: options.imgPath || _options.imgPath
    };
    return util;
  }

  var util = {
    checkMobile: checkMobile,
    checkCode: checkCode,
    pourtime: pourtime,
    imgNum: function(num) {
      return num;
    },
    urlNoPath: function() {
      return window.location.href.match(/https?:\/\/[^\/]+/i)[0];
    },
    render: function(adata, acolum) {
      var html = '';

      if (adata && acolum && adata.length > 0 && acolum.length > 0) {
        for (var i = 0; i < adata.length; i++) {
          html += '<tr>';
          for (var j = 0; j < acolum.length; j++) {
            if (typeof acolum[j] === 'string')
              html += '<td>' + adata[i][acolum[j]] + '</td>';
            else {
              var content = acolum[j](adata[i], i, adata);
              html += /<td.*<\/td>/.test(content) ? content : ('<td>' + content + '</td>');
            }
          }
          html += '</tr>';
        }
      }
      return html;
    },
    parseQueryString: function(url) {
      var reg_url = /^[^\?]+\?([\w\W]+)$/,
        reg_para = /([^&=]+)=([\w\W]*?)(&|$)/g, //g is very important
        arr_url = reg_url.exec(url),
        ret = {};
      if (arr_url && arr_url[1]) {
        var str_para = arr_url[1],
          result;
        while ((result = reg_para.exec(str_para)) != null) {
          ret[result[1]] = decodeURIComponent(result[2]);
        }
      }
      return ret;
    }
  }
  if (define.amd)
    define([], util);
  else
    window.Util = util;
}());
